<#assign ctx="${rc.contextPath}">

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>${Session.accTheme.accThemeTitle!"后台管理系统"}</title>
    <link rel="alternate icon" type="image/png" href="${ctx}/static/images/favicon.png">
    <link href="${ctx}/static/css/login.css" type="text/css" media="screen" rel="stylesheet"/>
    <script src="${ctx}/static/js/jquery.min.js"></script>
    <script src="${ctx}/static/js/jquery.cookie.js"></script>
    <style type="text/css">
        img, div {
            behavior: url(iepngfix.htc)
        }
    </style>
</head>

<body id="login">
<div id="wrappertop"></div>
<div id="wrapper">
    <div id="content">
        <div id="header">
            <h1><a href="#"><img src="${ctx}/static/images/logo.png" alt="logo"></a></h1>
        </div>
        <div id="darkbanner" class="banner320">
            <h2>用户登陆</h2>
        </div>
        <div id="darkbannerwrap">
        </div>
        <form id="loginMobile" name="form" method="post" action="${ctx}/doLogin">
            <fieldset class="form">
                <p>
                    <label for="username">用户名:</label>
                    <input name="username" id="username" type="text" onkeydown="enterSubmit()"/>
                </p>
                <p>
                    <label for="password">密码:</label>
                    <input name="password" id="password" type="password" onkeydown="enterSubmit()"/>
                </p>
                <div id="message" style="color: red"></div>
                <button type="button" onclick="login()" class="positive" name="登陆">
                    <img src="${ctx}/static/images/login/key.png" alt="Announcement"/>登陆
                </button>
                <ul id="forgottenpassword">
                    <li class="boldtext">|</li>
                    <li><a href="#">忘记密码?</a></li>
                </ul>
            </fieldset>
        </form>
    </div>
</div>

<div id="wrapperbottom_branding">
    <div id="wrapperbottom_branding_text"><a href="http://www.wuxuegai.com" style='text-decoration:none'>Powered
        By yang</a>
    </div>
</div>

<script type="text/javascript">

    $(function () {
        $("#username").focus();
        if ($.cookie("kmf_username")) {
            $("#username").val($.cookie("kmf_username"));
            $("#remember").attr("checked", "checked");
        }
    });

    var initScript = setInterval(function(){
        if (window.top!=null && window.top.document.URL!=document.URL){
            clearInterval(initScript);
            window.top.location.href = "${ctx}/index";
        }
    },400);

    function login() {
        if (validate($("#username").val(), "用户名不能为空") && validate($("#password").val(), "密码不能为空")) {
            $.ajax({
                type: "POST",
                url: $("#loginMobile").attr('action'),
                data: {username: $("#username").val(), password: $("#password").val()},
                dataType: "json",
                success: function (result) {
                    if (result.status == 200) {
                        if ($("#remember").prop("checked")) {
                            $.cookie('kmf_username', $("#username").val(), { expires: 7 });
                        } else {
                            $.removeCookie('kmf_username');
                        }
                        window.location.href = "${ctx}/index";
                    } else if (result.status == 201) {
                        $("#message").html("* " + result.message);
                        $("#message").css("visibility", "visible");
                    } else {
                        $("#content").html("* 用户名或密码错误，请重新输入");
                        $("#message").css("visibility", "visible");
                    }
                }
            });
        }
    }

    function validate(value, msg) {
        if (value.length < 1 || value.trim() == "") {
            $("#message").html("* " + msg);
            $("#message").css("visibility", "visible");
            return false;
        } else {
            return true;
        }
    }

    function enterSubmit() {
        var event = arguments.callee.caller.arguments[0] || window.event;//消除浏览器差异
        if (event.keyCode == 13) {
            login();
        }
    }

</script>
</body>
</html>